home *** CD-ROM | disk | FTP | other *** search
/ Amiga Tools 4 / Amiga Tools 4.iso / tools / mail-tools / thor / thor_2.22 / thor.lha / rexx / FTPGet.thor < prev    next >
Text File  |  1995-12-18  |  5KB  |  166 lines

  1. /*
  2. ** $VER: FTPGet.thor 1.0 (29.5.95)
  3. **
  4. ** by Eirik Nicolai Synnes
  5. **
  6. ** This script will let you select AmiNet files for ftp'ing either from a
  7. ** AmiNet RECENT listing produced by SortMail or from Thor's filebase. If
  8. ** the filebase window is open, the files selected there will be used.
  9. ** Otherwise FTPGet.thor will open a listview containing the RECENT listing.
  10. **
  11. ** FTPGet.thor is to be used together with FTPGet.daftp. The latter will
  12. ** read the list created by FTPGet.thor and get the files from the AmiNet
  13. ** site. Note that you will have to connect to the site yourself, but
  14. ** FTPGet.daftp will CD to the correct directory and start the downloading.
  15. **
  16. ** FTPGet.daftp has been tested with DaFTP 0.1130 and found to work
  17. ** satisfactory. FTPGet.thor needs Thor 2.0 or higher to work.
  18. **
  19. ** Before using these scripts, edit the listfile and getreadme variables
  20. ** below. FTPGet.daftp also contains two variables that must be edited
  21. ** before use.
  22. ** 
  23. */
  24.  
  25. /* Edit these variables: */
  26. listfile = 'Thor:GetFiles.txt'  /* This must be the same in FTPGet.thor and FTPGet.daftp */
  27. getreadme = 1                   /* 0 if you don't want readme's, 1 if you do */
  28. /* End */
  29.  
  30. options results
  31.  
  32. FDF_DELETED = '00000001'x
  33. path = ''
  34.  
  35. /* Open Thor and BBSREAD ARexx ports' */
  36. p=address()||' '||show('P',,);if pos('THOR.',p)>0 then thorport=word(substr(p,pos('THOR.',p)),1);else do;say 'No THOR port found!';exit(0);end
  37. if ~show('p', 'BBSREAD') then do; address command; "run >nil: `GetEnv THOR/THORPath`bin/LoadBBSRead"; "WaitForPort BBSREAD"; end
  38.  
  39. address(thorport)
  40. GETFILELIST OUTSTEM files
  41. select
  42.     when rc = 0 then do
  43.         CURRENTBBS STEM bbs
  44.         if rc > 1 then do
  45.             REQUESTNOTIFY '"'THOR.LASTERROR'"' '"Ok"'
  46.             exit(0)
  47.             end
  48.  
  49.         if exists(listfile) then call open(df, listfile, 'A')
  50.         else call open(df, listfile, 'W')
  51.  
  52.         do i=1 to files.COUNT
  53.             drop FILE. /* Important */
  54.  
  55.             address (bbsread)
  56.             SEARCHBRFILE '"'bbs.BBSNAME'"' FILE SEARCH '"'files.FILENAME.i'"' NAME
  57.             if rc ~= 0 then do
  58.                 address(thorport)
  59.                 REQUESTNOTIFY '"'BBSREAD.LASTERROR'"' '"Ok"'
  60.                 exit(0)
  61.                 end
  62.  
  63.             if FILE.FILEAREA.COUNT ~= 0 then do
  64.                 drop FTAGS.; drop FDATA.
  65.                 READBRFILE '"'bbs.BBSNAME'"' '"'FILE.FILEAREA.1'"' FILENR files.FILENR.i tagsstem FTAGS datastem FDATA
  66.                 if(rc ~= 0) then do
  67.                     address(thorport)
  68.                     REQUESTNOTIFY '"'BBSREAD.LASTERROR'"' '"Ok"'
  69.                     call close(df)
  70.                     exit(0)
  71.                     end
  72.  
  73.                 if bitand(DATA.FLAGS,FDF_DELETED) ~= FDF_DELETED then path = do
  74.                     path = FILE.FILEAREA.1'/'FTAGS.NAME
  75.                     if getreadme = 1 then do
  76.                         path = path' 'substr(path, 1, lastpos('.', subword(path, 1, 1)))'readme'
  77.                         end
  78.                     call writeln(df, path)
  79.                 end
  80.             end
  81.         call close(df)
  82.         end
  83.     when rc = 6 then do
  84.         REQUESTNOTIFY '"Please select some files."' '"Ok"'
  85.         end
  86.     when rc = 5 then do
  87.         /* Filebase not open, get Newfiles.txt if available */
  88.         CURRENTBBS STEM bbs
  89.         if rc > 1 then do
  90.             REQUESTNOTIFY '"'THOR.LASTERROR'"' '"Ok"'
  91.             exit(0)
  92.             end
  93.  
  94.         address(bbsread)
  95.         GETBBSDATA BBSNAME '"'bbs.BBSNAME'"' STEM bbsdata
  96.         if rc ~= 0 then do
  97.             address(thorport)
  98.             REQUESTNOTIFY '"'BBSREAD.LASTERROR'"' '"Ok"'
  99.             exit(0)
  100.             end
  101.  
  102.         if exists(bbsdata.BBSPATH'Newfiles.txt') then do
  103.             /* Open and read Newfiles.txt, skipping irrelevant lines */
  104.             call open(nf, bbsdata.BBSPATH'Newfiles.txt', 'R')
  105.             counter = 0
  106.             do until eof(nf)
  107.                 line = readln(nf)
  108.                 if left(line, 1) ~= '|' & line ~= '' then do
  109.                     counter = counter + 1
  110.                     entry.counter = line
  111.                     end
  112.                 end
  113.             call close(nf)
  114.             entry.count = counter
  115.  
  116.             if entry.count > 0 then do
  117.                 /* Put up a listview with the files */
  118.                 address(thorport)
  119.                 REQUESTLIST INSTEM entry OUTSTEM select TITLE '"Select files"' DRAGSELECT SIZEGADGET
  120.                 if rc ~= 0 then do
  121.                     if rc > 5 then do
  122.                         REQUESTNOTIFY '"'rc'\n'THOR.LASTERROR'"' '"Ok"'
  123.                         end
  124.                     exit(0)
  125.                     end
  126.  
  127.                 if select.COUNT = 0 then do
  128.                     /* One file was selected */
  129.                     path = subword(result, 2, 1)'/'subword(result, 1, 1)
  130.                     if substr(result, 35, 1) = '+' & getreadme = 1 then do
  131.                         path = path' 'substr(path, 1, lastpos('.', subword(path, 1, 1)))'readme'
  132.                         end
  133.                     if exists(listfile) then call open(df, listfile, 'A')
  134.                     else call open(df, listfile, 'W')
  135.                     call open(df, listfile, 'A')
  136.                     call writeln(df, path)
  137.                     call close(df)
  138.                     end
  139.  
  140.                 else do
  141.                     if exists(listfile) then call open(df, listfile, 'A')
  142.                     else call open(df, listfile, 'W')
  143.                     do i = 1 to select.COUNT
  144.                         /* Multiple files were selected */
  145.                         path = subword(select.i, 2, 1)'/'subword(select.i, 1, 1)
  146.                         if substr(select.i, 35, 1) = '+' & getreadme = 1 then do
  147.                             path = path' 'substr(path, 1, lastpos('.', subword(path, 1, 1)))'readme'
  148.                             end
  149.                         call writeln(df, path)
  150.                     end
  151.                     call close(df)
  152.                     end
  153.                 end
  154.             end
  155.         else do
  156.             /* No Newfiles.txt found */
  157.             REQUESTNOTIFY '"No new files on system."' '"Ok"'
  158.             end
  159.         end
  160.     otherwise do
  161.         REQUESTNOTIFY '"'THOR.LASTERROR'"' '"Ok"'
  162.         end
  163.     end
  164.  
  165. exit(0)
  166.